package com.captain.special.二叉树.简单;

import com.captain.leetcode.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * Des:
 *
 * @author XL
 * @Date 2022/5/7 8:40
 */
public class 左叶子之和404 {
    public int sumOfLeftLeaves(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        recur(root, res);
        int sum = 0;
        for (Integer re : res) {
            sum = sum + re;
        }
        return sum;
    }

    public void recur(TreeNode node, List<Integer> res) {
        if (node == null) {
            return;
        }
        if (node.left != null && node.left.left == null && node.left.right == null) {
            res.add(node.left.val);
        }
        recur(node.left, res);
        recur(node.right, res);
    }
}
